<?php

require __DIR__.'/vendor/autoload.php';

echo "测试树形结构转换\n";
echo "================\n\n";

$converter = new App\Services\TreeConverter();

$data = [
    ["id" => 200002538, "name" => "空心菜类", "level" => 3, "namePath" => "蔬菜/豆制品,叶菜类,空心菜类"],
    ["id" => 200002537, "name" => "香菜类", "level" => 3, "namePath" => "蔬菜/豆制品,葱姜蒜椒/调味菜,香菜类"],
    ["id" => 200002536, "name" => "紫苏/苏子叶", "level" => 3, "namePath" => "蔬菜/豆制品,叶菜类,紫苏/苏子叶"],
    ["id" => 200002543, "name" => "乌塌菜/塌菜/乌菜", "level" => 3, "namePath" => "蔬菜/豆制品,叶菜类,乌塌菜/塌菜/乌菜"],
    ["id" => 200002542, "name" => "菜心/菜苔类", "level" => 3, "namePath" => "蔬菜/豆制品,叶菜类,菜心/菜苔类"],
    ["id" => 200002540, "name" => "马兰头/马兰/红梗菜", "level" => 3, "namePath" => "蔬菜/豆制品,叶菜类,马兰头/马兰/红梗菜"],
    ["id" => 200002531, "name" => "苋菜类", "level" => 3, "namePath" => "蔬菜/豆制品,叶菜类,苋菜类"],
    ["id" => 200002528, "name" => "其他叶菜类", "level" => 3, "namePath" => "蔬菜/豆制品,叶菜类,其他叶菜类"]
];

echo "原始数据:\n";
echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";

echo "转换后的树形结构:\n";
$tree = $converter->convertToTreeStructure($data);
echo $converter->formatTreeOutput($tree) . "\n";

// 测试随机ID生成
echo "\n测试随机ID生成:\n";
for ($i = 0; $i < 5; $i++) {
    echo "随机ID: " . $converter->generateRandomId() . "\n";
}